/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package kivuli.visao.dialog;

import kivuli.entidade.Predio;
import kivuli.visao.FramePrincipal;

/**
 *
 * @author bpmlab
 */
public class DialogPredio extends javax.swing.JDialog {

    private final Predio predio;
    private boolean ok;
    
    public DialogPredio(FramePrincipal framePrincipal, Predio predio) {
        super(framePrincipal, true);
        this.predio = predio;
        initComponents();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    public void valoresPadroes() {
        if (predio != null) {
            txAndares.setText(predio.getAndares() + "");
            txComprimento.setText(predio.getComprimento() + "");
            txLargura.setText(predio.getLargura() + "");
        }
    }

    public Predio getPredio() {
        return predio;
    }

    public boolean isOk() {
        return ok;
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbLargura = new javax.swing.JLabel();
        lbComprimento = new javax.swing.JLabel();
        lbAndares = new javax.swing.JLabel();
        txLargura = new javax.swing.JTextField();
        txComprimento = new javax.swing.JTextField();
        txAndares = new javax.swing.JTextField();
        btnOk = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Configurar Prédio");
        setResizable(false);

        lbLargura.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbLargura.setText("Largura: ");

        lbComprimento.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbComprimento.setText("Comprimento: ");

        lbAndares.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbAndares.setText("Andare(s): ");

        btnOk.setText("Ok");
        btnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnCancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnOk))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(lbLargura, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lbComprimento, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lbAndares, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txLargura, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                            .addComponent(txComprimento)
                            .addComponent(txAndares))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbLargura)
                    .addComponent(txLargura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbComprimento)
                    .addComponent(txComprimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbAndares)
                    .addComponent(txAndares, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 17, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnOk))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
        int andares = Integer.parseInt(txAndares.getText());
        int comprimento = Integer.parseInt(txComprimento.getText());
        int largura = Integer.parseInt(txLargura.getText());
        
        predio.setAndares(andares);
        predio.setComprimento(comprimento);
        predio.setLargura(largura);
        
        this.dispose();
        ok = true;
    }//GEN-LAST:event_btnOkActionPerformed


    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnOk;
    private javax.swing.JLabel lbAndares;
    private javax.swing.JLabel lbComprimento;
    private javax.swing.JLabel lbLargura;
    private javax.swing.JTextField txAndares;
    private javax.swing.JTextField txComprimento;
    private javax.swing.JTextField txLargura;
    // End of variables declaration//GEN-END:variables
}
